Add concept of track line colors. Currently supported only for an1->kml. More
authorrobertl <robertl>
Sat, 16 Aug 2008 17:43:05 +0000 (17:43 +0000)
committerrobertl <robertl>
Sat, 16 Aug 2008 17:43:05 +0000 (17:43 +0000)
to come later.

an1.c
defs.h
kml.c

diff --git a/an1.c b/an1.c
index c499b12b49a64055d8d11293cba9d08a02549c69..f7b85a57048e6d30436b9af3b8c4c009bafb4720 100644 (file)
--- a/an1.c
+++ b/an1.c
@@ -1,6 +1,6 @@
 /*
     Read DeLorme drawing files (.an1)
+
     Copyright (C) 2005 Ron Parker and Robert Lipe.
 
     This program is free software; you can redistribute it and/or modify
@@ -224,7 +224,7 @@ typedef struct {
        long lineweight;
        long linestyle;
        long linecolor;
-       long unk5;
+       long opacity;
        long polyfillcolor;
        long unk6;
        long unk7;
@@ -532,7 +532,7 @@ static void Read_AN1_Line( gbfile *f, an1_line_record *line ) {
        line->lineweight = ReadShort( f );
        line->linestyle = ReadLong( f );
        line->linecolor = ReadLong( f );
-       line->unk5 = ReadLong( f );
+       line->opacity = ReadLong( f );
        line->polyfillcolor = ReadLong( f );
        line->unk6 = ReadLong( f );
        line->unk7 = ReadLong( f );
@@ -555,7 +555,7 @@ static void Write_AN1_Line( gbfile *f, an1_line_record *line ) {
        WriteShort( f, (short) line->lineweight );
        WriteLong( f, line->linestyle );
        WriteLong( f, line->linecolor );
-       WriteLong( f, line->unk5 );
+       WriteLong( f, line->opacity );
        WriteLong( f, line->polyfillcolor );
        WriteLong( f, line->unk6 );
        WriteLong( f, line->unk7 );
@@ -797,6 +797,15 @@ static void Read_AN1_Lines( gbfile *f ) {
                Read_AN1_Line( f, rec );
                /* create route rec */
                 rte_head = route_head_alloc();
+                rte_head->line_color.bbggrr = rec->linecolor;
+                if (rec->opacity == 0x8200)
+                  rte_head->line_color.opacity = 128;
+                // lineweight isn't set for dashed/dotted lines
+                // Since we don't have a way to represent this internally yet,
+                // use leave line_width at the default.
+                if(rec->lineweight)
+                  rte_head->line_width = rec->lineweight;
+                rte_head->rte_name = xstrdup(rec->name);
                fs_chain_add( &rte_head->fs, (format_specific_data *)rec );
                 route_add_head(rte_head);
                for (j = 0; j < (unsigned) rec->pointcount; j++ ) {
@@ -847,7 +856,7 @@ Write_One_AN1_Line( const route_head *rte )
        fs = fs_chain_find( rte->fs, FS_AN1L );
        
        if ( fs ) {
-               rec = (an1_line_record *)(void *)fs;    
+               rec = (an1_line_record *)(void *)fs;
                local = 0;
                switch (output_type_num) {
                        case 1:
@@ -918,7 +927,7 @@ Write_One_AN1_Line( const route_head *rte )
                                rec->unk4 = 2;
                                rec->lineweight = 6;
                                rec->linecolor = opt_color_num; /* red */
-                               rec->unk5 = 3;
+                               rec->opacity = 3;
                                rec->unk8 = 2;
                                break;
                }
diff --git a/defs.h b/defs.h
index 40932e7b58143776c6c7048cb7013c3f02d21c90..c4ded48de4a9ac397d7e8efb7bdc26c8e9a346d9 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -289,6 +289,12 @@ typedef struct format_specific_data {
        fs_convert convert;
 } format_specific_data;
 
+typedef struct {
+  int bbggrr;   // 32 bit color: Blue/Green/Red.  < 0 == unknown.
+  unsigned char opacity;  // 0 == transparent.  255 == opaque.
+} gb_color;
+
+
 format_specific_data *fs_chain_copy( format_specific_data *source );
 void fs_chain_destroy( format_specific_data *chain );
 format_specific_data *fs_chain_find( format_specific_data *chain, long type );
@@ -452,6 +458,8 @@ typedef struct {
        int rte_waypt_ct;               /* # waypoints in waypoint list */
        format_specific_data *fs;
        unsigned short cet_converted;   /* strings are converted to UTF8; interesting only for input */
+        gb_color line_color;         /* Optional line color for rendering */
+        int line_width;         /* in pixels (sigh).  < 0 is unknown. */
 } route_head;
 
 /*
diff --git a/kml.c b/kml.c
index c72c34a426be9781925b4eee3454b216f0bae8e7..e81790b59a46e507403ae23542bd1e0feb3bc71c 100644 (file)
--- a/kml.c
+++ b/kml.c
@@ -717,6 +717,17 @@ static void kml_output_tailer(const route_head *header)
     kml_write_xml(1, "<Placemark>\n");
     kml_write_xml(0, "<name>Path</name>\n");
     kml_write_xml(0, "<styleUrl>#lineStyle</styleUrl>\n");
+    if (header->line_color.bbggrr >= 0 || header->line_width >= 0) {
+      kml_write_xml(1, "<Style>\n");
+      kml_write_xml(1, "<LineStyle>\n");
+      if (header->line_color.bbggrr >= 0)
+        kml_write_xml(0, "<color>%02x%06x</color>\n",
+                      header->line_color.opacity, header->line_color.bbggrr);
+      if (header->line_width >= 0)
+        kml_write_xml(0, "<width>%d</width>\n",header->line_width);
+      kml_write_xml(-1, "</LineStyle>\n");
+      kml_write_xml(-1, "</Style>\n");
+    }
     kml_write_xml(1, "<LineString>\n");
     if (floating) {
       kml_write_xml(0, "<altitudeMode>absolute</altitudeMode>\n");